//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import com.itheima.reggie.service.ShoppingCartService;
import com.itheima.reggie.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/order"})
public class OrderController {
    private static final Logger log = LoggerFactory.getLogger(OrderController.class);
    @Autowired
    private OrderService orderService;
    @Autowired
    private ShoppingCartService shoppingCartService;
    @Autowired
    private UserService userService;

    public OrderController() {
    }

    @PostMapping({"/submit"})
    public R<String> submit(@RequestBody Orders orders) {
        log.info("订单数据：{}", orders);
        this.orderService.submit(orders);
        return R.success("下单成功");
    }

    @GetMapping({"/userPage"})
    public R Oder1(int page, int pageSize) {
        IPage<Orders> P = new Page((long)page, (long)pageSize);
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.orderByDesc(Orders::getOrderTime);
        this.orderService.page(P, queryWrapper);
        return R.success(P);
    }

    @GetMapping({"/page"})
    public R Oder2(int page, int pageSize, Orders orders) {
        IPage<Orders> P = new Page((long)page, (long)pageSize);
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(orders.getNumber() != null, Orders::getNumber, orders.getNumber());
        queryWrapper.orderByDesc(Orders::getOrderTime);
        this.orderService.page(P, queryWrapper);
        return R.success(P);
    }
}
